﻿using System;
using System.Collections.Generic;
using Autodesk.Revit.DB;
using RevitInteractiveUtility.ExternalEventManager;

namespace FetchDataCompare
{
	public class AddBoundaryRequest : IRequest
	{
		public int RequestId
		{
			get
			{
				return 1;
			}
		}

		public void DoRequest(object parameters = null)
		{
			AddBoundaryBean addBoundaryBean = null;
			if (parameters is AddBoundaryBean)
			{
				addBoundaryBean = (parameters as AddBoundaryBean);
			}
			this.DarwBoundary(addBoundaryBean.LstCheckReportData, addBoundaryBean.SrcDocM, addBoundaryBean.DesDocM);
		}

		public void DarwBoundary(List<ReportData> LstCheckReportData, DocumentManger m_SrcDocM, DocumentManger m_DesDocM)
		{
            GraphicsStyle lineStyle = Utlity.GetLineStyle(m_SrcDocM.UseDoc, "BoundaryLineType", new Autodesk.Revit.DB.Color(byte.MaxValue, 0, 0), 5);
            GraphicsStyle lineStyle2 = Utlity.GetLineStyle(m_DesDocM.UseDoc, "BoundaryLineType", new Autodesk.Revit.DB.Color(byte.MaxValue, 0, 0), 5);
			foreach (ReportData reportData in LstCheckReportData)
			{
				if (reportData.SrcObjectStructBase != null)
				{
					Transaction transaction = new Transaction(m_SrcDocM.UseDoc, "Create Boundary");
					try
					{
						transaction.Start();
						reportData.SrcObjectStructBase.DrawOutLine(lineStyle, true);
						transaction.Commit();
					}
					catch (Exception)
					{
						transaction.RollBack();
					}
					Transaction transaction2 = new Transaction(m_DesDocM.UseDoc, "Create Boundary");
					try
					{
						transaction2.Start();
						if (reportData.DesObjectStructBase == null)
						{
							reportData.SrcObjectStructBase.DrawOutLine(m_DesDocM.UseDoc, lineStyle2, false);
							transaction2.Commit();
						}
						else
						{
							reportData.DesObjectStructBase.DrawOutLine(lineStyle2, false);
							transaction2.Commit();
						}
					}
					catch (Exception)
					{
						transaction2.RollBack();
					}
				}
				if (reportData.DesObjectStructBase != null)
				{
					Transaction transaction3 = new Transaction(m_DesDocM.UseDoc, "Create Boundary");
					try
					{
						transaction3.Start();
						reportData.DesObjectStructBase.DrawOutLine(lineStyle2, false);
						transaction3.Commit();
					}
					catch (Exception)
					{
						transaction3.RollBack();
					}
					Transaction transaction4 = new Transaction(m_SrcDocM.UseDoc, "Create Boundary");
					try
					{
						transaction4.Start();
						if (reportData.SrcObjectStructBase == null)
						{
							reportData.DesObjectStructBase.DrawOutLine(m_SrcDocM.UseDoc, lineStyle, true);
							transaction4.Commit();
						}
						else
						{
							reportData.SrcObjectStructBase.DrawOutLine(lineStyle, true);
							transaction4.Commit();
						}
					}
					catch (Exception)
					{
						transaction4.RollBack();
					}
				}
			}
		}
	}
}
